<template>
	<view class="home">
		<!-- 自定义导航栏组件 -->
		<navbar ></navbar>
		<!-- 选项卡组件 -->
		<tab :list="tabList" @tab="tab" :tabIndex="tabIndex"></tab>
		<view class="home-list">
			<list :tab="tabList" :activeIndex="activeIndex" @change="change"></list>
		</view>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		computed: {
			...mapState(['userinfo'])
		},
		watch: {
			userinfo(newVal){
				this.getLabel()
			}
		},
		data() {
			return {
				"msg": "Hello uni-app",
				tabList: [],
				tabIndex: 0,
				activeIndex: 0
			}
		},
		onLoad() {
			uni.$on('labelChange',(res) => {
				this.tabList = []
				this.tabIndex = 0
				this.activeIndex = 0
				this.getLabel()
			})
		},
		methods: {
			getLabel(){
				this.$api.get_label({
					
				}).then(res => {
					const {data} = res
					
					data.unshift({
						name: '全部'
					})
					
					this.tabList = data
				})
				
			},
			tab({data,index}){
				this.activeIndex = index
			},
			change(current){
				this.activeIndex = current
				this.tabIndex = current
			}
		},
		/* components: {
			navbar
		} */
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		display: flex;
	}
	.home{
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: hidden;
		.home-list{
			flex: 1;
			box-sizing: border-box;
		}
	}
</style>
